package app

import (
	"fmt"
	"net/http"

	"github.com/gin-gonic/gin"
	"o78k.cn/dapi/app/entity"
	"o78k.cn/dapi/core"
	"o78k.cn/dapi/models"
)

func init() {
	POST("/login", func(c *gin.Context) {
		var data entity.LoginForm = entity.LoginForm{}
		c.ShouldBindJSON(&data)
		var user = models.User{}
		core.Database.Where("user_name = ?", data.User).First(&user)
		if user.Password != data.Password {
			c.JSON(http.StatusOK, gin.H{
				"message": "password error",
			})
			return
		}
		fmt.Print(data)
		c.JSON(http.StatusOK, gin.H{
			"message": "Hello, world!",
		})
	})

	GET("/logout", func(c *gin.Context) {
		c.JSON(http.StatusOK, gin.H{
			"message": "Hello, world!",
		})
	})
}
